﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientAppViaWebService.DivisionsLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class ManagingDivisionEditForm : DivisionEditForm
    {
        private readonly Int32 ClassID = 10;

        #region Properties.

        public string BossName
        {
            get { return txtBossName.Text; }
            set { txtBossName.Text = value; }
        }

        public DateTime DateCreated
        {
            get
            {
                return dtpDateCreated.Value;
            }
            set { dtpDateCreated.Value = value; }
        }

        public String Description
        {
            get  { return txtDescription.Text; }
            set { txtDescription.Text = value; }
        }       

        #endregion

        public ManagingDivisionEditForm()
        {
            InitializeComponent();
            divisionLogicService = new DivisionsLogicService();
        }

        protected override void SetFormProperties(Object _object)
        {
            Division d = (_object as Division);
            ID = d.ID;
            EXT_ID = d.EXT_ID;
            ParentId = d.PARENT_ID;
            Class = d.CLASS_ID;
            ObjName = d.NAME;
            BossName = d.BOSS_ID;
            DateCreated = d.DATE_CREATED;
            Description = d.DESCRIPTION;
        }

        protected override Object RetrieveFormProperties()
        {
            Division division = new Division();
            division.ID = ID;
            division.EXT_ID = EXT_ID;
            division.PARENT_ID = ParentId;
            division.CLASS_ID = Class;
            division.NAME = ObjName;
            division.DataBaseName = DataBaseName;
            division.BOSS_ID = BossName;
            division.DATE_CREATED = DateCreated;
            division.DESCRIPTION = Description;
         
            return division;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            Division p = divisionLogicService.SelectDivision_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            Division obj = RetrieveFormProperties() as Division;
            divisionLogicService.UpdateDivision(obj);
        }

        protected override void InsertEntity()
        {
            Division obj = RetrieveFormProperties() as Division;
            divisionLogicService.InsertDivision(obj);
        }
    }
}
